<template>
  <el-dialog
    custom-class="custom-dialog"
    :class="{ border: true, fullscreen: fullscreen }"
    :width="width"
    :title="title"
    :fullscreen="fullscreen"
    append-to-body
    :close-on-click-modal="clickClose"
    @opened="$emit('opened')"
    @closed="$emit('closed')"
    :destroy-on-close="closeFree"
    v-model="_value"
  >
    <!--    <slot name="title"></slot>-->
    <slot></slot>
    <template #footer>
      <div v-if="showFooter">
        <el-button @click="handelCancel">取消</el-button>
        <el-button type="primary" @click="handelConfirm">确定</el-button>
      </div>
    </template>
  </el-dialog>
</template>

<script>
export default {
  name: "WDialog",
  components: {},
  props: {
    title: {
      type: String,
      default: ""
    },
    width: {
      type: String,
      default: "50%"
    },
    fullscreen: Boolean,
    noPadding: {
      type: Boolean,
      default: false
    },
    modelValue: {
      type: Boolean,
      default: false
    },
    clickClose: {
      type: Boolean,
      default: false
    },
    closeFree: {
      type: Boolean,
      default: false
    },
    showFooter: {
      type: Boolean,
      default: true
    },
    cancelText: {
      type: String,
      default: "取 消"
    },
    okText: {
      type: String,
      default: "确 定"
    },
    okLoading: false,
    border: {
      type: Boolean,
      default: true
    }
  },
  computed: {
    _value: {
      get() {
        return this.modelValue;
      },
      set(val) {
        this.$emit("update:modelValue", val);
      }
    }
  },
  data() {
    return {};
  },
  methods: {
    handelCancel() {
      this._value = false;
      this.$emit("cancel");
    },
    handelConfirm() {
      this.$emit("ok");
    }
  }
};
</script>

<style lang="scss" scoped>
:deep(.custom-dialog) {
  .el-dialog__header {
    padding: 10px 20px;
    .el-dialog__title {
      font-size: 17px;
    }
    .el-dialog__headerbtn {
      top: 15px;
      .i {
        font-size: large;
      }
    }
  }

  .el-dialog__footer {
    padding: 10px 20px;
  }
}

.border {
  :deep(.el-dialog__header) {
    border-bottom: 1px solid #e8e8e8;
  }
  :deep(.el-dialog__footer) {
    border-top: 1px solid #e8e8e8;
  }
}

.fullscreen {
  overflow: hidden;
  :deep(.el-dialog) {
    margin-top: 0 !important;
    width: 100% !important;
    .el-dialog__body {
      padding: 0;
      height: calc(100vh - 94px);
    }
  }
}
</style>
